package com.sinux.sshUser.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.fasterxml.jackson.annotation.JsonIgnore;


/**
 * @author WangGan
 * @version 2017年5月16日 下午5:08:32
 * 角色类
 */



@Entity
@Table(name = "role")
@DynamicInsert(true)
@DynamicUpdate(true)
public class Role {
	private String roid;
	private String roname;
	@JsonIgnore
	private Set<User> users = new HashSet<User>();
	@JsonIgnore
	private Set<Department> departs=new HashSet<Department>();
	@JsonIgnore
	private Set<Resources> resours=new HashSet<Resources>();
	@JsonIgnore
	private Set<Permission> permits=new HashSet<Permission>();
	
	@Id
	@Column(name = "ro_id", unique = true,nullable = false, length = 64)
	public String getRoid() {
		return roid;
	}
	public void setRoid(String roid) {
		this.roid = roid;
	}
	
	@Column(name = "ro_name", nullable = false, length = 64)
	public String getRoname() {
		return roname;
	}
	public void setRoname(String roname) {
		this.roname = roname;
	}
	
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name="re_user_role",joinColumns={
			@JoinColumn(name="ro_id",nullable=false,updatable=false)},inverseJoinColumns={
					@JoinColumn(name="u_id",nullable=false,updatable=false)})
	public Set<User> getUsers() {
		return users;
	}
	public void setUsers(Set<User> users) {
		this.users = users;
	}
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="re_role_department",joinColumns={
			@JoinColumn(name="ro_id",nullable=false,updatable=false)},inverseJoinColumns={
					@JoinColumn(name="de_id",nullable=false,updatable=false)})
	public Set<Department> getDeparts() {
		return departs;
	}
	
	public void setDeparts(Set<Department> departs) {
		this.departs = departs;
	}
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="re_role_resources",joinColumns={
			@JoinColumn(name="ro_id",nullable=false,updatable=false)},inverseJoinColumns={
					@JoinColumn(name="re_id",nullable=false,updatable=false)})
	public Set<Resources> getResours() {
		return resours;
	}
	public void setResours(Set<Resources> resours) {
		this.resours = resours;
	}
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="re_role_permission",joinColumns={
			@JoinColumn(name="ro_id",nullable=false,updatable=false)},inverseJoinColumns={
					@JoinColumn(name="per_id",nullable=false,updatable=false)})
	public Set<Permission> getPermits() {
		return permits;
	}
	public void setPermits(Set<Permission> permits) {
		this.permits = permits;
	}
	
	
	

}
